package controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;

import util.UrlUtility;
import bizlogic.PriorityManager;
import java.util.ArrayList;
import model.PriorityDTO;

@WebServlet("/LoadPriority")
public class LoadPriorityServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public LoadPriorityServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		processRequest(request, response);
	}
	
	private void processRequest(HttpServletRequest request, HttpServletResponse response) {
		PriorityManager pm = new PriorityManager();
		ArrayList<PriorityDTO> pDTO = pm.getAll();
		request.setAttribute("priority", pDTO);
		
		UrlUtility.forwardPage(request, response, "/WEB-INF/ShowPriority.jsp");
	}
}
